package com.yh.action;

import com.yh.entity.User;
import com.yh.services.IUserService;
import com.yh.services.impl.UserServiceImpl;
import com.yh.util.BaseAction;
import lombok.Data;

import java.io.IOException;

import static com.opensymphony.xwork2.Action.SUCCESS;

@Data
public class AddUserAction extends BaseAction {
    private String uname;
    private String repwd;

    public String execute() throws IOException {
        IUserService iUserService=new UserServiceImpl();
        User user=new User();
        user.setCol_Name(uname);
        user.setCol_Pwd(repwd);

      User u= iUserService.getUserByIud(user);
      if (u==null){
          int b=iUserService.addUser(user);
          if (b>0){
              return SUCCESS;
          }else {
              getResponse().getWriter().print("alert('用户已存在')");
              return "out";
          }
      }else {
          getResponse().getWriter().print("alert('用户已存在')");
          return "out";
      }
    }
}
